#include <mysql.h>
#include <stdio.h>

#define MYSQL_SERVER_IP		"localhost"
#define MYSQL_USR_NAME		"kimi"
#define MYSQL_USR_PWD		"123abc//"
#define MYSQL_SERVER_PORT	3306


int main(void){
	//printf("%s\n",mysql_get_client_info());
	MYSQL *con=mysql_init(NULL);
	int query_ret;
	if(con==NULL){fprintf(stderr,"%s\n",mysql_error(con));return 0;}
	if( (mysql_real_connect(con,MYSQL_SERVER_IP,MYSQL_USR_NAME,MYSQL_USR_PWD,NULL,MYSQL_SERVER_PORT,NULL,0)) == NULL ){
		fprintf(stderr,"%s\n",mysql_error(con));
		return 0;
	}
	mysql_query(con,"DROP DATABASE test_db");
	if( (mysql_query(con,"CREATE DATABASE test_db")) != 0 ){
		fprintf(stderr,"%s\n",mysql_error(con));
		return 0;
	}
	mysql_query(con,"USE test_db");
	mysql_query(con,"drop table if exists `tb_order`");
	query_ret=mysql_query(con,"create table `tb_order` ( tb_order_id INT PRIMARY KEY,order_year VARCHAR(4),\
		order_code VARCHAR(30),station_id VARCHAR(5),send_date VARCHAR(20),\
		receive_date VARCHAR(20) )");
	if(query_ret==0){printf("Table tb_order create!\n");}
	mysql_query(con,"drop table if exists `order_info`");
	query_ret=mysql_query(con,"create table `order_info` ( tb_order_id INT,order_id INT,operate CHAR(1),\
		  start_date VARCHAR(20),end_date VARCHAR(20),start_time VARCHAR(8),end_time VARCHAR(8),\
		  days VARCHAR(7),order_type_name VARCHAR(16),order_type CHAR(2),channel VARCHAR(3),antenna_prog_id VARCHAR(3),\
		  freq INT,azimuth VARCHAR(5),actual_power VARCHAR(4),op_status VARCHAR(2),trans_name VARCHAR(3),\
		  ant_used_code VARCHAR(3),reason VARCHAR(100),station_name VARCHAR(20),prog_desc VARCHAR(20),\
		  program_name VARCHAR(10),ant_prog_desc VARCHAR(10),feedback_status VARCHAR(2),\
		  actual_start VARCHAR(20),modu VARCHAR(2),PRIMARY KEY(tb_order_id,order_id) ) ");
	if(query_ret==0){printf("Table order create!\n");}
	else{fprintf(stderr,"%s\n",mysql_error(con));}
	mysql_close(con);
	return 0;
}
